<?php namespace Home\Controller; 

use Hdphp\Controller\Controller;

//首页控制器
class ContentController extends Controller{
	private $model;
	private $goodsattr;
	//构造函数
	public function __init(){
		$this->model=new \Common\Model\goods;
		$this->goodsattr=new \Common\Model\goodsattr;
	}
	
    //动作
    public function index(){
    	//接收传递过来的id
    	$gid=Q('get.gid',0,'intval');
		//接收数据库数据
		$goodsData=$this->model->join('goodsdetail','gid','=','goods_gid')->where("goods_gid={$gid}")->find();
		//字符串转化为数组
		$goodsData['dimg']=explode('|',$goodsData['dimg']);
		View::with('goodsData',$goodsData);
//		p($goodsData);
		//实例化商品属性表
		$attrModel=new \Common\Model\Goodsattr;
		//商品属性表关联类型属性表
		$attrData=$attrModel->join('t_attr','t_attr_taid','=','taid')->where("goods_gid={$gid} AND type=1")->get();
		//p($attrData);
		$data=array();
		foreach ($attrData as $k=>$v){
			$data[$v['attname']][]=$v;
		}
//		p($data);
		
		View::with('data',$data);
		View::make();
    }
	//ajax获得属性
	public function getAttr(){
		//接收组合的属性id
		$specs=rtrim(Q('post.spec'),',');
		
		//接收组合的加价
		$price=rtrim(Q('post.price'),',');
	
		//把发送过来的价格组合成数组
		$arr=explode(',', $price);
		$num=0;
		//循环数组价格相加
		foreach ($arr as $v){
			$num=$num+$v;
		}
//		$arrs = array(
//			'num' => $num,
//		);
//		p($num);
		//返回数据
		echo json_encode($num);exit;
	}
	public function addCart(){
		$data=Q('post.msg1');
		p($data);
		$data=$this->goodsattr->where("gaid in ({$data})")->get();
		p($data);
		
		
	}




}
